<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>添加友链</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="//cdn.staticfile.org/layui/2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<form class="layui-form layuimini-form" lay-filter="plugin-info">
    <div class="layui-form-item">
        <label class="layui-form-label">名称:</label>
        <div class="layui-input-block">
            <input name="name" placeholder="友链名称"
                   lay-verify="required" lay-reqtext="名称不得为空"
                   class="layui-input"/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">地址:</label>
        <div class="layui-input-block">
            <input name="url" placeholder="友链地址" value=""
                   lay-verify="required" lay-reqtext="地址不能为空"
                   class="layui-input" required>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">权重:</label>
        <div class="layui-input-block">
            <input type="number" name="weight" placeholder="请填写权重" value=""
                   lay-verify="required" lay-reqtext="权重不能为空"
                   class="layui-input" required>
            <tip>填数字，数字越大排名越前。</tip>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">是否显示:</label>
        <div class="layui-input-block">
            <input type="checkbox" value="1" name="enable" lay-skin="switch" lay-filter="switchTest" lay-text="ON|OFF" checked>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="saveBtn">确认添加</button>
        </div>
    </div>
</form>
<script src="//cdn.staticfile.org/layui/2.6.3/layui.js" charset="utf-8"></script>
<script src="../../js/api.js?v=1.0.0" charset="utf-8"></script>
<script src="../../js/common.js?v=1.0.0" charset="utf-8"></script>
<script>
    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer;
        //监听提交
        form.on('submit(saveBtn)', function (data) {
            layer.load(1)
            data.field.enable = data.field.enable ? 1 : 0;
            httpPost('/admin/link/add', data.field).then(res => {
                if (res.status === 'ok') {
                    $message.success('添加成功');
                    const index = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(index);
                }
            }).finally(() => {
                layer.closeAll('loading')
            })
            return false;
        });

    });
</script>
</body>
</html>